//
//  UpdateView.m
//  CarsFiles_QYB
//
//  Created by 程虎 on 2017/8/7.
//  Copyright © 2017年 程虎. All rights reserved.
//

#import "UpdateView.h"

@implementation UpdateView

- (instancetype)initWithUpdateNotice:(NSString *)noticeStr
{
    self  = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, 290, 321);
        [self set_UI:noticeStr];
    }
    return self;
}

- (void)set_UI:(NSString *)noticeStr
{
    UIView *views = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H)];
    views.backgroundColor = [UIColor clearColor];
    
    UIImageView *update_img = [UIImageView new];
    update_img.image = [UIImage imageNamed:@"update_img"];
    update_img.userInteractionEnabled = YES;
    
    UILabel *lab = [[Tools shareInstance] creat_Label:noticeStr Color:K_TitlesColor Font:15 tag:-1 Alignment:0 Lines:0];
    //    lab.attributedText = [[Tools shareInstance] setLabelLineSpaceTextString:@"1、流程界面新增“帮助”按钮，可查询附近服务中心情况\n2、车生活新增警广之声模块\n3、优化理赔模块的提示语。"];
    
    UIButton *updateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [updateBtn setTitle:@"立即升级" forState:0];
    [updateBtn setTitleColor:[UIColor whiteColor] forState:0];
    [updateBtn setBackgroundColor:KButtonColor];
    [updateBtn addTarget:self action:@selector(jumpToSafari) forControlEvents:1 << 6];
    LRViewRadius(updateBtn, 7.5, 0.5, [UIColor clearColor]);
    [update_img sd_addSubviews:@[lab,updateBtn]];
    [views addSubview:update_img];
    
    CGFloat left = 28;
    CGFloat m_top = 170;
    
    update_img.sd_layout
    .centerXEqualToView(views)
    .centerYEqualToView(views)
    .widthIs(290);
    
    lab.sd_layout
    .leftSpaceToView(update_img, left)
    .topSpaceToView(update_img, m_top)
    .rightSpaceToView(update_img, left)
    .autoHeightRatio(0);
    
    updateBtn.sd_layout
    .leftSpaceToView(update_img, left)
    .topSpaceToView(lab, 22.5)
    .rightSpaceToView(update_img, left)
    .heightIs(44);
    
    [update_img setupAutoHeightWithBottomView:updateBtn bottomMargin:19.5];
}

- (void)jumpToSafari
{
    NSString *downURL = nil;
    if (Application_Types == 0) {
        downURL = DownLoadURL;
    }
    else {
        downURL = DownLoadURL_AppStore;
    }
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:downURL]];
}

@end
